package com.liyuan.help_e.dao;

import com.liyuan.help_e.model.News;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

@Mapper
@Repository
public interface NewsDao {
    @Select("select * from news order by publishTime desc limit #{size} offset #{offset}")
    News[] selectNewsByPage(@Param("offset") int i,
                            @Param("size") Integer size);

    @Select("select count(*) from news")
    Integer sumAllNews();

    @Select("select * from news order by publishTime limit #{size}")
    News[] selectNewsByReadCount(@Param("size") Integer size);

    @Select("select * from news where id = #{id}")
    News selectNewsById(@Param("id") Integer id);

    @Insert("insert into news(publishTime,title,url,author,content,imageUrl,readCount)values(#{publishTime},#{title},#{url},#{author},#{content},#{imageUrl},#{readCount})")
    void insertNews(News news);

    @Select("select * from news where imageUrl!='' order by publishTime desc limit #{number}")
    News[] selectNewsByScale(@Param("number") Integer number);
}
